﻿using System;
using System.Collections.Generic;
using System.Text;
using Ozner.Common;
using Ozner.Model;
using HtmlAgilityPack;
namespace Ozner.BLL
{
    public class IndexInfomationBLL : BaseBLL
    {
        private string URL = "/IndexInfomation.aspx";
        private string SystemNoticURL = "/handler/SystemNoticeHandler.ashx?oper=all";
        private HtmlDocument Document = null;
        public BaseResult<User> GetLoginUser()
        {
            BaseResult<User> bsv = GetLoginedDocument<User>(URL);
            if (bsv.Code == Code.OK)
            {
                Document = bsv.OtherInfo as HtmlDocument;
                HtmlNode hnName = Document.DocumentNode.SelectSingleNode("//form[@id='form1']/div[4]/div[2]/div[1]/table[1]/tr[1]/td[2]");
                HtmlNode hnAccount = Document.DocumentNode.SelectSingleNode("//form[@id='form1']/div[4]/div[2]/div[1]/table[1]/tr[2]/td[2]");
                User user = new User();
                if (hnName != null)
                {
                    user.Name = hnName.InnerText;
                }
                if (hnAccount != null)
                {
                    user.Account = hnAccount.InnerText;
                }
                bsv.Code = Code.OK;
                bsv.Object = user;

            }

            return bsv;
        }

        public BaseResult<JsonBaseResult<SystemNotice>> GetSystemNotice()
        {
            BaseResult<JsonBaseResult<SystemNotice>> bsv = PostLoginedJson<JsonBaseResult<SystemNotice>>(SystemNoticURL,"IsPub=1&IsAdmin=0&page=1&pagesize=100");
            return bsv;
        }
    }
}
